home *** CD-ROM | disk | FTP | other *** search
- Path: atglab.bls.com!Alun.Champion
- From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
- Newsgroups: comp.lang.c++
- Subject: Re: Function body banned in .H file - Can I still inline?
- Date: 10 Jan 1996 20:00:56 GMT
- Organization: Computer People Inc.
- Message-ID: <ALUN.CHAMPION.96Jan10150056@g7240065.bridge.bst.bls.com>
- References: <4d0ir0$68e@newsroom.hitc.com> <4d0u0a$gc7@news.cis.nctu.edu.tw>
- NNTP-Posting-Host: bstfirewall.bst.bls.com
- In-reply-to: terryt@mcs.com's message of 10 Jan 1996 17:45:46 GMT
-
- In article <4d0u0a$gc7@news.cis.nctu.edu.tw> terryt@mcs.com (Terry Trippany) writes:
-
- : In article <4d0ir0$68e@newsroom.hitc.com>, cruegger@eos.hitc.com says...
- :>
- :> I am not permitted to put any function bodies into the .H file for a class.
- :> Question:
- :> I would still like to make the small accessor routines inline. What
- :> is my recourse, if any?
-
- : If you want to make a function inline without putting the source in the
- : header then you can use the inline keyword. BE AWARE that this is just a hint
- The source still needs to be in the header if it is to be inlined in
- other translation units - see below.
-
- : to the compiler and it may or may not treat it as inline depending on which
- : compiler you use.
-
- : eg:
- : // file foo.hpp
-
- : class Foo
- : {
- : void myFunc();
- : }
-
- : // file foo.cpp
-
- : inline void Foo::myFunc() { ... }
-
- : You could also specify the inline keyword in the declaration file if that's
- : where you would like to put it.
-
- This will only make the function inline - in that particular translation
- unit and not for the whole application.
-
- [*excpert from standard*]
- 7.1.2 Function specifiers
- ...
- 3 An inline function shall be defined in every translation unit it is used
- (3.2), and shall have exactly the same definition in every case (see one
- definition rule, 3.2). ...
-
- This basically says the function definition must be visible at compile time
- to be made inline and as such should probably best go into the header file
- to guarentee the same definition in every translation unit.
-
- Regards
-
- -A.
-
-
-
- --
- | A.Champion |
-